package com.flyxteam.learner.springboot.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.flyxteam.learner.springboot.config.PlanConfig;
import com.flyxteam.learner.springboot.config.TeamConfig;
import com.flyxteam.learner.springboot.data.SomeData;

// ## 一个rest-api
@RestController
public class SomeApiController {

    @RequestMapping(path = "/api", method = RequestMethod.GET)
    Object api() {
        Map<String, Object> result = new HashMap<>();
        result.put("title", "hello, spring boot examples api");
        result.put("author", "flyxteam");
        return result;
    }
    
    // some properties
    
    @Autowired
    TeamConfig teamConfig;
    
    @RequestMapping(path = "/team", method = RequestMethod.GET)
    Object team() {
        return teamConfig;
    }
    
    @Autowired
    PlanConfig planConfig;
    
    @RequestMapping(path = "/plan", method = RequestMethod.GET)
    Object plan() {
        return planConfig;
    }
    
    // some endpoint
    
    @Autowired
    SomeData someData;
    
    @RequestMapping(path = "/info", method = RequestMethod.POST)
    Object info(String name) {
        someData.getInfo().put("name", name);
        return "ok";
    }

}
